#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/9/16 15:20
# @Author  : AshJo
# @Desc    : 斐波那契数列练习
# @Filename: fibonacci.py.py
# @Version : v1.0
"""


# 生成器，产生数列的值
# def fib(n):
#     if n == 1:
#         yield 1
#     else:
#         yield from (1, 1)
#         a, b = 1, 1
#         while n > 2:
#             a, b = b, a + b
#             yield b
#             n -= 1
#
#
# for i in fib(3):
#     print(i)

# 递归函数，返回对应数列的值
def fib(n, a=1, b=1):
    if n == 1 or n == 2:
        return b
    else:
        a, b = b, a + b
        return fib(n - 1, a, b)


print(fib(5))
